#ifndef SENSORWORKER_H
#define SENSORWORKER_H

#include <QObject>
#include <MCDLL_NET.h>

class SensorWorker : public QObject
{
    Q_OBJECT
public:
    explicit SensorWorker(ushort di, ushort d0, QObject *parent = nullptr)
        : QObject(parent), m_di(di), m_do(d0), m_running(true) {}

    virtual void stop() = 0;
    virtual void process() = 0;

signals:
    void finished();
    void log(const QString& message);

protected:
    ushort m_di;
    ushort m_do;
    bool m_running;

    // 公共功能方法
    void clearInputEdge();
    void setOutputBit(ushort state);
    void setTimedOutput(ushort state, ushort duration);
    bool checkInputEdge(ushort &edgeCount);
    bool checkInputLevel(ushort &level);
    long getEncoderCount();
    void waitForEncoderCount(long targetCount);
};

#endif // SENSORWORKER_H
